package cn.kp.learning.service.Impl;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.kp.learning.dao.CoreUserOrgRoleDao;
import cn.kp.learning.model.CoreUserOrgRole;
import cn.kp.learning.model.CoreUserOrgRoleExample;
import cn.kp.learning.model.CoreUserOrgRoleExample.Criteria;
import cn.kp.learning.service.CoreUserOrgRoleService;
@Service("cuorService")
public class CoreUserOrgRoleServiceImpl implements CoreUserOrgRoleService {

	@Resource
	private CoreUserOrgRoleDao coreUserOrgRoleDao;
	@Override
	public int addCuor(CoreUserOrgRole cuor) {
		int insertResult = 0;
		CoreUserOrgRoleExample ce = new CoreUserOrgRoleExample();
		Criteria criteria = ce.createCriteria();
		criteria.andOrgCompanyIdEqualTo(cuor.getOrgCompanyId());
		criteria.andOrgDepartmentIdEqualTo(cuor.getOrgDepartmentId());
		criteria.andOrgOfficeIdEqualTo(cuor.getOrgOfficeId());
		criteria.andOrgGroupIdEqualTo(cuor.getOrgGroupId());
		criteria.andUserNameEqualTo(cuor.getUserName());
		criteria.andRolesIdEqualTo(cuor.getRolesId());
		List<CoreUserOrgRole> lt = coreUserOrgRoleDao.selectByExample(ce);
		System.out.println(cuor.getOrgCompanyId()+"-"+cuor.getOrgDepartmentId()+"-"+cuor.getOrgOfficeId()+"-"+cuor.getOrgGroupId()+"-"+cuor.getUserName()+"-"+cuor.getRolesId());
		System.out.println("addcuor before select:"+lt.size());
		if(lt.size()>0){
			
		}else{
			insertResult = coreUserOrgRoleDao.insertSelective(cuor);
		}
		return insertResult;
	}

	@Override
	public int deleteCuor(CoreUserOrgRole cuor) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateCuor(CoreUserOrgRole cuor) {
		// TODO Auto-generated method stub
		return coreUserOrgRoleDao.updateByPrimaryKeySelective(cuor);
	}

	@Override
	public List<CoreUserOrgRole> getCuorList(CoreUserOrgRoleExample example) {
		// TODO Auto-generated method stub
		return coreUserOrgRoleDao.selectByExample(example);
	}

	@Override
	public CoreUserOrgRole getCuor(HashMap<String, Object> hm) {
		// TODO Auto-generated method stub
		return coreUserOrgRoleDao.selectByPrimaryKey(hm);
	}

	@Override
	public int countCuor(CoreUserOrgRoleExample example) {
		// TODO Auto-generated method stub
		return coreUserOrgRoleDao.countByExample(example);
	}


}
